<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 13-11-8
 * Time: 上午9:50
 * 显示票付通会员列表
 */
use \pft\Member\MemberAccount as Mem;
if($_SESSION['memberID']!=1 && !($_SESSION['sid']==1 && strpos($_SESSION['qx'],'mems'))){
    exit("不合法的身份访问！");
}
include '/var/www/html/new/d/common/autoload.php';
include COMMONPATH.'page.php';
$mem = new Mem($GLOBALS['le'],0, SoapInit::GetSoapInside());

$LD = array('供应商','分销商','资源方',5=>'普通会员',6=>'员工',7=>'集团');
$LS = array('正常','<span style="color:#F63">禁用</span>',
    '<span style="#F00">删除</span>','<span style="color:#00F">未审核</span>');

$currentPage =$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize    =$_REQUEST["pageSize"]?$_REQUEST["pageSize"]:10;
$offset     =($currentPage-1)*$pageSize;
if($_REQUEST['act']=='loadExcel'){
    $offset = 0;
    $pageSize = 99999;
}
$params = array(
    'dtype'=> '0,1',
    'limit'=> $offset,
    'offset'=> $pageSize,
);

if($_SERVER['REQUEST_METHOD']=='GET') {
    $st = intval($_GET['searchType']);
    switch($st) {
        case 1:
            $params['dname'] = safetxt($_GET['squery']);
            break;
        case 2:
            $params['cname'] = safetxt($_GET['squery']);
            break;
        case 3:
            $params['mobile'] = safetxt($_GET['squery']);
            break;
        case 4:
            $params['alipay'] = safetxt($_GET['squery']);
            break;
        case 5:
            $params['id'] = intval($_GET['squery']);
            break;
        case 6:
            $params['dcode'] = safetxt($_GET['squery']);
            break;
        case 7:
            $params['account'] = safetxt($_GET['squery']);
            break;
        case 8:
            $params['com_name'] = safetxt($_GET['squery']);
            break;
        default:break;
    }

    if($_GET['dtype']>-1){
        $params['dtype'] = intval($_GET['dtype']);
    }
    if(($_GET['status'])>-1){
        $params['status'] = intval($_GET['status']);
    }
    $params['bt1'] = safetxt($_GET['btime1']);
    $params['et1'] = safetxt($_GET['etime1']);
    $params['et1'].=' 23:59:59';
    if(isset($_GET['group_id'])){
        $params['group_id'] = intval($_GET['group_id']);
    }
}
if(isset($_POST['gid']) && !empty($_POST['mid'])) {
    $son_id_type_L = array(0=>3, 1=>0);//供应商、分销商
//    print_r($_POST);exit;
    foreach($_POST['mid'] as $mid) {
        $mdata = explode('|', $mid);
        $id = $mdata[0];
        $son_id_type = $son_id_type_L[$mdata[1]];
        $ret = $mem->createRelationship($_POST['gid'], $id, $son_id_type, 1);
        //TODO:如果集团添加供应商，则默认将该供应商的所有分销商与集团建立关系
        if($son_id_type==3) {
            $fxs = $mem->gemMemRShip($id);
            foreach($fxs as $fx) {
                $ret2 = $mem->createRelationship($_POST['gid'], $fx['son_id'], 0, 1);
                if($ret2['status']!='ok') {
                    echo "<script>alert('{$ret['msg']}');</script>";
                    exit;
                }
            }
        }
        //var_export($ret);
        if($ret['status']!='ok') {
            echo "<script>alert('{$ret['msg']}');</script>";
            exit;
        }
    }
    echo '<script>alert("添加成功！");</script>';
    exit;
}

try{
    $mem_list = $mem->getMemList($params, false);
    $total_rows = $mem->getMemList($params, true);
   print_r($mem_list);
} catch(Exception $e) {
    echo $e->getMessage();
}

$ids = $alliance = array();
foreach($mem_list as $k=>$ct){
    $ids[]=$ct['id'];
}
if(count($ids)){
    $sql="SELECT id,fid FROM pft_distributor_union_SE WHERE fid IN (".implode(',',$ids).")";
    $GLOBALS['le']->query($sql);
    while($row=$GLOBALS['le']->fetch_assoc()){
        $alliance[]=$row['fid'];
    }
}
// print_r($alliance);
// print_r($mem_list);
if($_REQUEST['act']=='loadExcel'){
    $filename=date('YmdHis').'会员列表';
    // $Excel[0]['a']='编号';
    $Excel[0]['b']='身份';
    $Excel[0]['c']='企业名';
    $Excel[0]['d']='账号';
    // $Excel[0]['e']='接口编码';
    $Excel[0]['f']='联系人';
    $Excel[0]['g']='手机';
    $Excel[0]['h']='账户余额';
    $Excel[0]['i']='支付宝账号';
    $Excel[0]['j']='状态';
    $Excel[0]['k']='创建时间';
    $i=1;
    foreach($mem_list as $data){
        //print_r($row);
        $n++;
        // $Excel[$n]['a']=$data['id'];
        $Excel[$n]['b']=$LD[$data['dtype']];
        $Excel[$n]['c']=$data['dname'];
        $Excel[$n]['d']=$data['account'];
        // $Excel[$n]['e']='';
        $Excel[$n]['f']=$data['cname'];
        $Excel[$n]['g']=$data['mobile'];
        $dname = urlencode($data['dname']);
        $money = $mem->ShowBalance($data['id'])/100;

        $Excel[$n]['h']=$money;
        $Excel[$n]['i']=$data['alipay'];
        $Excel[$n]['j']=$LS[$data['status']];
        $Excel[$n]['k']=$data['creattime'];
    }
    $xls = new SimpleExcel('UTF-8', true,'ml');
    $xls->addArray($Excel);
    $xls->generateXML($filename);
    exit;
}
$page_title = '票付通平台会员列表';
$crtAuth_txt = array(//
	'未认证','认证中','已认证','认证未通过'
);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script language="javascript" src="/js/jquery-1.8.0.min.js"></script>
    <title>会员列表 - 票付通分销平台</title>
</head>
<body>
<link rel="stylesheet" href="/css/aliceui.min.css"/>
<link rel="stylesheet" href="/css/resetui.css"/>
<link rel="stylesheet" href="/css/page.css"/>
<link rel="stylesheet" href="css/list.css"/>
<style type="text/css">
    .dname_input{
        border:0 none;
    }
    .red{
        color:#FF0000;
    }
    .green{
        color:#009005;
    }
    .gray{
        color:#999;
    }
    .fenyeiWrap{
        clear: none;
    }
    .ui-table td{
        border-bottom:1px solid #999;
    }
    .com_type{
        color: #b70725;
    }
    .pinput-txt{
        width: 200px; height: 22px;line-height: 22px;border:1px solid #CCC;
    }
    .pinput-txt_a{
        width: 50px; height: 20px;line-height: 20px;border:1px solid #CCC;margin-top:5px;margin-bottom:5px;
    }
    .pinput-txt_b{
        width: 25px; height: 20px;line-height: 20px;border:1px solid #CCC;margin-top:5px;margin-bottom:5px;
    }
    h4{text-align:center;}
    .wid80{ width: 90px; height: 20px;line-height: 20px;border:1px solid #CCC;margin-top:5px;margin-right:10px;margin-bottom:5px;}
    .wid90{ width: 50px; height: 20px;line-height: 20px;border:1px solid #CCC;margin-top:5px;margin-left:35px;margin-bottom:5px;}
    .tl_z{margin-right:25px;}
    .tl_f{margin-left:25px;}
    .tips{margin-left:-20px;}
    .tl{margin-left:15px;}
    p {line-height: 3;}
    .grp_red{color: red}
</style>
<div class="wrap">
    <form name="ourform" class="search_form ">
        <input name="gid" type="hidden" value="<?=$_GET['gid']?>"/>
        <input name="act" type="hidden" id="act"/>
        <input name="group_id" type="hidden" id="group_id" value="<?=$_REQUEST['group_id']?>"/>
        <fieldset class="search-box">
            <legend>会员查询</legend>
            <table class="search-tbl" cellspacing="0">
                <tr>
                    <td class="tab1">
                        <label class="t">查询条件:</label>
                        <select name="searchType" id="search1">
                            <option value="-1">--请选择--</option>
                            <option value="8" <?=$_GET['searchType']==8? 'selected':'';?>>企业名称</option>
                            <option value="1" <?=$_GET['searchType']==1? 'selected':'';?>>账号名称</option>
                            <option value="7" <?=$_GET['searchType']==7? 'selected':'';?>>账号</option>
                            <option value="2" <?=$_GET['searchType']==2? 'selected':'';?>>姓名</option>
                            <option value="3" <?=$_GET['searchType']==3? 'selected':'';?>>手机号</option>
                            <option value="5" <?=$_GET['searchType']==5? 'selected':'';?>>ID</option>
                            <option value="6" <?=$_GET['searchType']==6? 'selected':'';?>>接口编码</option>
                            <option value="4" <?=$_GET['searchType']==4? 'selected':'';?>>支付宝账号</option>


                        </select>
                        <input type="text" name="squery" class="input-txt" id="squery" value="<?=$_GET['squery']?>"/>
                    </td>
                    <td class="tab2">
                        <label class="t">会员类型</label>
                        <select name="dtype">
                            <option value="-1">选择</option>
                            <option value="0" <?=isset($_GET['dtype']) && $_GET['dtype']==0? 'selected':'';?>>供应商</option>
                            <option value="1" <?=$_GET['dtype']==1? 'selected':'';?>>分销商</option>
                            <option value="2" <?=$_GET['dtype']==2? 'selected':'';?>>资源方</option>
                            <option value="5" <?=$_GET['dtype']==5? 'selected':'';?>>普通会员</option>
                            <option value="6" <?=$_GET['dtype']==6? 'selected':'';?>>员工</option>
                            <option value="7" <?=$_GET['dtype']==7? 'selected':'';?>>集团</option>
                        </select>
                    </td>
                    <td>
                        <label class="t">状态</label>
                        <select name="status">
                            <option value="-1">选择</option>
                            <option value="0" <?=$_GET['status']==0? 'selected':'';?>>正常</option>
                            <option value="1" <?=$_GET['status']==1? 'selected':'';?>>禁用</option>
                            <option value="3" <?=$_GET['status']==3? 'selected':'';?>>未审核</option>
                            <option value="2" <?=$_GET['status']==2? 'selected':'';?>>删除</option>
                        </select>
                    </td>
                    <td>
                        <div>
                            <label class="t">注册时间:</label>
                            从<input readonly="readonly" class="t1 tt1 w80 input-txt" type="text" name="btime1" onfocus="SelectDate(this,'yyyy-MM-dd',0,0)" value="<?=$params['bt1']?>"/>
                            至<input type="text" class="t2 tt1 w80 input-txt" readonly="readonly" name="etime1" onfocus="SelectDate(this,'yyyy-MM-dd',0,0)" value="<?=$params['et1']?>"/>
                        </div>
                        <div>
                            <label class="t">登录时间:</label>
                            从<input readonly="readonly" class="t1 tt1 w80 input-txt" type="text" name="btime2" onfocus="SelectDate(this,'yyyy-MM-dd',0,0)" value="<?=$params['bt2']?>"/>
                            至<input type="text" class="t2 tt1 w80 input-txt" readonly="readonly" name="etime2" onfocus="SelectDate(this,'yyyy-MM-dd',0,0)" value="<?=$params['et2']?>"/>
                        </div>
                    </td>
                    <td>
                        <button id="searchBtn" type="button" class="ui-button ui-button-lorange" >查  找</button>
                        <button id="ExcelBtn" type="button" class="ui-button ui-button-lorange_a">导  出</button>
                    </td>
                </tr>
            </table>
            <span id="search_kind">账户类型：
            <a class="" key="group_id" kvalue="">全部</a>
            <a class="<?=$_GET['group_id']==1?'grp_red':''?>" key="group_id" kvalue="1">普通帐号</a>
            <a class="<?=$_GET['group_id']==6?'grp_red':''?>" key="group_id" kvalue="6">签约账号</a>
            <a class="<?=$_GET['group_id']==2?'grp_red':''?>" key="group_id" kvalue="2">测试账户</a>
            <a class="<?=$_GET['group_id']==3?'grp_red':''?>" key="group_id" kvalue="3">内部点餐账号</a>
            <a class="<?=$_GET['group_id']==4?'grp_red':''?>" key="group_id" kvalue="4">云顶账户</a>
            <a class="<?=$_GET['group_id']==5?'grp_red':''?>" key="group_id" kvalue="5">鼓浪屿账户</a>
            </span>
        </fieldset>
    </form>
    <!---->
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post" target="hideFrame">
        <div class="ui-table-container">
            <table class="ui-table ui-table-noborder"><!-- 可以在class中加入ui-table-inbox或ui-table-noborder分别适应不同的情况 -->
                <thead>
                <tr>
                    <th>ID</th>
                    <!--<th>创建时间</th>-->
                    <th>身份</th>
                    <th style="width:10%;">账户名称</th>
                    <th>企业名称</th>
                    <th>帐号</th>
                    <th>接口编码</th>
                    <th>联系人</th>
                    <th>公司简称</th>
                    <th>手机</th>
                    <th>账户余额</th>
                    <th>支付宝账号</th>
                    <th>状态</th>
                    <th>认证状态</th>
                    <th>登录/创建时间</th>
                    <?if(!$_GET['gid']):?>
                        <th>操作</th>
                    <?endif;?>
                </tr>
                </thead>
                <tbody id="mem_list_tbd">
                <?foreach($mem_list as $list):?>
                    <?
                    $dname = urlencode($list['dname']);
                    $money = $mem->ShowBalance($list['id'])/100;
                    if($money>0) $m_c = 'red';
                    elseif($money<0) $m_c = 'green';
                    else $m_c = 'gray';
                    ?>
                    <tr>
                        <td class="mid" data-mid="<?=$list['id']?>">
                            <input type="checkbox" name="mid[]" value="<?=$list['id'].'|'.$list['dtype']?>"/>
                            <?=$list['id']?>
                            <br/><a href="javascript:;" data-id="<?=$list['id']?>" class="edit">修改</a>
                        </td>
                        <td><?=$LD[$list['dtype']]?></td>
                        <td id="editInfo_<?=$list['id']?>" data-ast="<?=$list['add_saler_type']?>" data-jt-acc="<?=$list['jiutian_auth']?>" data-refund_back="<?=$list['refund_back']?>" data-group_id="<?=$list['group_id']?>">
                            [<span class="com_type"><?=$list['com_type']?></span>]
                            <span class="dname"><?=$list['dname']?></span>
                            </td>
                        <td id="editInfo_c<?=$list['id']?>">
                            <span class="com_name"><?=$list['com_name']?></span>
                        </td>
                        <td><?=$list['account']?></td>
                        <td id="dcode_<?=$list['id']?>"><?=$list['dcode']?></td>
                        <td><span class="sex" data-fid="<?=$list['eid'].'|'.$list['fid']?>"><?=$list['sex']=='M'? '[先生]':'[女士]'?></span><?=$list['cname']?></td>
                        <td><?=$list['short_company_name']?></td>
                        <td><?=$list['mobile']?></td>
                        <td><span class="<?=$m_c?>"><?=$money?></span></td>
                        <td><?=$list['alipay']?></td>
                        <td class="status"><?=$LS[$list['status']]?></td>
                        <td class="status"><?=$crtAuth_txt[$list['certi_status']]?></td>
                        <td>登录:<?=$list['lasttime']?><br/>创建:<?=$list['creattime']?></td>
                        <?if(!$_GET['gid']):?>
                            <td>
                                <?if($list['dtype']==7):?>
                                    <a target="_blank" href="/g_info.html?id=<?=$list['id']?>">详情</a>
                                    <a target="_blank" href="relations.php?t=<?=$dname?>&id=<?=$list['id']?>&type=3&group=1">成员</a>
                                <?else:?>
                                    <?if($list['dtype']==0):?>
                                        <a target="_blank" href="relations.php?t=<?=$dname?>&id=<?=$list['id']?>&type=1">分销商</a>
                                        <a target="_blank" href="relations.php?t=<?=$dname?>&id=<?=$list['id']?>&type=2">资源方</a>
                                    <?endif;?>
                                    <?if($list['dtype']==1 || $list['dtype']==0 ):?>
                                        <a target="_blank" href="/rechDist.html?id=<?=$list['id']?>">充值</a>
                                    <?endif;?>
                                    <a target="_blank" href="relations.php?t=<?=$dname?>&id=<?=$list['id']?>&type=0">供应商</a>
                                    <br/>
                                    <a target="_blank" href="relations.php?t=<?=$dname?>&id=<?=$list['id']?>&type=3">员工</a>
                                    <a target="_blank" href="/userinfo.html?id=<?=$list['id']?>">详情</a>

                                    <?if($list['status']==3):?>
                                        <a href="javascript:;" class="verify" data-status="0">通过</a>
                                        <a href="javascript:;" class="verify" data-status="1">拒绝</a>
                                    <? elseif($list['status']==0):?>
                                        <a href="javascript:;" class="verify" data-status="1">禁用</a>
                                    <?elseif($list['status']==1):?>
                                        <a href="javascript:;" class="verify" data-status="0">启用</a>
                                    <?endif;?>
                                <?endif;?>
                                <a target="_blank" href="/saleList.html?id=<?=$list['id']?>">售卖产品</a>
                            </td>
                        <?endif;?>
                    </tr>
                <?endforeach;?>
                </tbody>
            </table>
            <div class="list-foot">
                <?if(isset($_GET['gid']) && is_numeric($_GET['gid'])):?>
                    <input name="gid" type="hidden" value="<?=$_GET['gid']?>"/>
                    <iframe id="hideFrame" name="hideFrame" src="about:blank"
                            frameborder="0" style="display: none;width: 0;height: 0;"></iframe>
                    <div class="left" style="float: left; width: 100px;">
                        <button type="submit" >合并供应商到集团</button>
                    </div>
                <?endif;?>
                <?page($total_rows,$currentPage,$pageSize);?>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript" src="/js/Calendar.js"></script>
<script type="text/javascript" src="/js/moment.min.js"></script>
<script type="text/javascript" src="/js/d.js"></script>
<link rel="stylesheet" href="/css/easydialog.css"/>
<script type="text/javascript" src="/js/easydialog.min.js"></script>
<script type="text/javascript" src="admin.js"></script>
</body>
</html>
